package space.xxhui.oomdemo.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.widget.ImageView;

/**
 * Created by hui on 2016/10/19.
 */

public class ImageAsyncTask extends AsyncTask<String,Void,Bitmap> {
    private ImageView imageView;
    private Context context;


    public ImageAsyncTask(ImageView imageView,Context context ) {
        this.imageView = imageView;
        this.context  = context;
    }

    @Override
    protected Bitmap doInBackground(String... params) {
        Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),Integer.parseInt(params[0]));
        LruCacheUtils.getInstance().addBitmapToMemoryCache(params[0],bitmap);
        Bitmap lruBitmap = LruCacheUtils.getInstance().getBitmapFromMemCache(params[0]);
        return lruBitmap;
    }

    @Override
    protected void onPostExecute(Bitmap bitmap) {
        super.onPostExecute(bitmap);
        imageView.setImageBitmap(bitmap);
    }
}
